package myapp.Chat;

import staticClass.XmppConnection;
import myapp.EnumAndConstans.Constants;
import myapp.googlemap.R;
import myapp.services.ChatServiceHelper;
import android.app.Dialog;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class AddFriendDialog extends Dialog implements android.view.View.OnClickListener{
	
	private XmppClient xmppClient;
	
	public AddFriendDialog(XmppClient client) {
		super(client);
		// TODO Auto-generated constructor stub
		this.xmppClient = client;
	}
	
	@Override
	protected void onStart() {
		// TODO Auto-generated method stub
		super.onStart();	
		
		Initialize();
	}
	
	private void Initialize(){
		setContentView(R.layout.chat_add_friend_dialog);
		getWindow().setFlags(Constants.WINDOW_FLAG_FOR_DIALOG, Constants.WINDOW_MASKS_FOR_DIALOG);
		setTitle("ADD NEW FRIENDS");
		
		SetClickListeners();
	}
	
	private void SetClickListeners(){
		Button btnSendAddFriendRq = (Button) findViewById(R.id.chat_send_add_friend_request);
		btnSendAddFriendRq.setOnClickListener(this);		
	}
	
	public void onClick(View v){
		String friendEmail = getText(R.id.chat_friend_email);
		ChatServiceHelper helper = new ChatServiceHelper();
		if (friendEmail.length() > Constants.MINIMUM_MAIL_LENGTH){
			Log.i("AddFriendDialog", "[onClick]: user:" + XmppConnection.userEmail + " friend:" + friendEmail);
			helper.sendFriendRequest(XmppConnection.userEmail, friendEmail);			
		}
		dismiss();
	}
	
	private String getText(int id) {
		EditText widget = (EditText) this.findViewById(id);
		return widget.getText().toString();
	}
}
